<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>


<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';
import 'echarts/theme/macarons'; // echarts theme
import resize from './mixins/resize';



const className = ref('chart');
const width = ref('100%');
const height = ref('300px');
let chart = null;

onMounted(() => {
  initChart();
});

onBeforeUnmount(() => {
  if (!chart) return;
  chart.dispose();
  chart = null;
});

function initChart() {
  chart = echarts.init(document.querySelector('.chart'), 'macarons');

  chart.setOption({
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    legend: {
      left: 'center',
      bottom: '10',
      data: ['Industries', 'Technology', 'Forex', 'Gold', 'Forecasts']
    },
    series: [
      {
        name: 'WEEKLY WRITE ARTICLES',
        type: 'pie',
        roseType: 'radius',
        radius: [15, 95],
        center: ['50%', '38%'],
        data: [
          { value: 320, name: 'Industries' },
          { value: 240, name: 'Technology' },
          { value: 149, name: 'Forex' },
          { value: 100, name: 'Gold' },
          { value: 59, name: 'Forecasts' }
        ],
        animationEasing: 'cubicInOut',
        animationDuration: 2600
      }
    ]
  });
}
</script>
